package com.example.trb.service.performance;

import com.example.trb.dto.ObjectDTO;
import com.example.trb.entity.PerformancePatent;
import com.example.trb.mapper.PerformancePatentMapper;
import com.example.trb.util.result.SysReturnCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PerformancePatentService {
    @Autowired
    PerformancePatentMapper ppMapper;

    public ObjectDTO update(PerformancePatent data) {
        ppMapper.updateById(data);
        return new ObjectDTO(null, SysReturnCode.OK);
    }

    public ObjectDTO removeById(Integer id) {
        ppMapper.deleteById(id);
        return new ObjectDTO(null, SysReturnCode.OK);
    }

    public ObjectDTO updateStatusById(Integer id, String status) {
        ppMapper.updateStatusById(id, status);
        return new ObjectDTO(null, SysReturnCode.OK);
    }

    public ObjectDTO save(PerformancePatent data) {
        ppMapper.insert(data);
        return new ObjectDTO(data.getId(), SysReturnCode.OK);
    }

    public ObjectDTO getById(Integer id) {
        PerformancePatent result = ppMapper.selectById(id);
        return new ObjectDTO(result, SysReturnCode.OK);
    }

    public List<PerformancePatent> listByReviewFormId(Integer id) {
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("review_form_id", id);
        List<PerformancePatent> result = ppMapper.selectByMap(queryMap);
        return result;
    }
}
